package arithmetic;

/**
 * 快速排序
 * @author: yyfei  
 * @email:  yyfei123@qq.com
 */
public class ArrayKuaiSuPaiXu {
	public static void main(String[] args) {
		
	}
	
	/**
	 * 元素交换
	 * @author: yyfei
	 * @email:  yyfei123@qq.com
	 */
	public static void swap(int[] data,int i,int j) {
		int temp=data[i];
		data[i]=data[j];
		data[j]=temp;
	}
	
	public static void subSort(int[] data,int start,int end) {
		if(start<end) {
			int base=data[start];
			int low=start;
			int hight=end+1;
			while(true) {
				while(low<end && data[++low]-base<=0);
				while(hight>start && data[--hight]-base>=0);
				if(low<hight) {
					swap(data,low,hight);
				}else {
					break;
				}
			}
			swap(data,start,hight);
			subSort(data,start,hight-1);
			subSort(data,hight+1,end);
		}
	}
	//快速排序
	public static void quickSort(int[] data) {
		subSort(data, 0, data.length-1);
	}
	
	
}
